//
//  YViewController.swift
//  rxCoreLogic
//
//  Created by yq on 2021/1/21.
//

import UIKit
import EFMarkdown
import EFCMark
import RxSwift
import RxCocoa
import Toast

class YViewController: UIViewController {

	let disposeBag = DisposeBag()
	
	private let markView = EFMarkdownView()
	public var markdown = "" {
		didSet {
			loadMarkdown(with: markdown)
		}
	}
	/// 请求 markdown 格式
	/// - Parameter mark: markdown 字符串
	public func loadMarkdown(with mark: String) {
		markView.load(markdown: mark, options: [.hardBreaks]) {
			[weak self] (_, _) in
			guard let self = self else { return }
			
			self.markView.setFontSize(percent: 120)
			printLog("load finish!")
		}
	}
	
	override func viewDidLoad() {
		super.viewDidLoad()

		configureNavgationBar(isTransparent: nil)
	}
	
	func setupMarkView() {
		markView.frame = view.bounds
		self.view.addSubview(markView)
	}
	
}


//MARK: - ✨== Others ==✨
extension YViewController {
		
	override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
		view.endEditing(true)
	}

	func showHud(string: String) {
		self.view.makeToast(string, position: ToastPosition.center)
	}
}

//MARK: - ✨== 设置导航栏 ==✨
extension YViewController {
	
	func configureNavgationBar(isTransparent: Bool?) {
		guard let isTrans = isTransparent else { return }
		if isTrans {
			// 透明
			self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
			// 取出黑线
			self.navigationController?.navigationBar.shadowImage = UIImage()
		}
	}
}

